package xyz.weizhi.controller;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import xyz.weizhi.domain.CODE;
import xyz.weizhi.domain.result;
import xyz.weizhi.exception.BusinessException;
import xyz.weizhi.exception.SystemException;

/**
 * @Author milian
 * @Date 2021/9/15 0015 15:54
 */
@RestControllerAdvice
public class ProjectExceptionAdvice {
    //@ExceptionHandler用于设置当前处理器类对应的异常类型
    @ExceptionHandler(SystemException.class)
    public result doSystemException(SystemException ex){
        //记录日志

//发送消息给运维
//发送邮件给开发人员,ex对象发送给开发人员
        return new result(ex.getCode(),null,ex.getMessage());
                }

@ExceptionHandler(BusinessException.class)
public result doBusinessException(BusinessException ex){
        return new result(ex.getCode(),null,ex.getMessage());
        }

//除了自定义的异常处理器，保留对Exception类型的异常处理，用于处理非预期的异常
@ExceptionHandler(Exception.class)
public result doOtherException(Exception ex){
        //记录日志
        //发送消息给运维
        //发送邮件给开发人员,ex对象发送给开发人员
        return new result(CODE.SYSTEM_UNKNOW_ERR,null,"系统繁忙，请稍后再试！");
        }
        }